//
//  MessageDetController.m
//  PropertyMananger
//
//  Created by bh on 17/3/13.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "MessageDetController.h"

@interface MessageDetController ()

@property (nonatomic,strong) UILabel * timeLable;


@end

@implementation MessageDetController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    [self initTitleViewName:@"消息"];
    
    [self createDetailUI];
    
    [self postMessageDetailData];
    
}
- (void)createDetailUI{

    UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 10, BHscreenW-20, BHscreenH-64-20)];
//    scrollView.layer.borderWidth = 0.5;
//    scrollView.layer.borderColor = BHColor(102, 102, 102).CGColor;
//    scrollView.backgroundColor = [UIColor whiteColor];
//    scrollView.layer.cornerRadius = 5;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:scrollView];
    
    float w = scrollView.frame.size.width;
    //标题
   self.titleLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, w, 25)];
    self.titleLable.textAlignment = NSTextAlignmentCenter;
    self.titleLable.text = self.model.Title;
    self.titleLable.textColor = BHColor(102, 102, 102);
    self.titleLable.font = [UIFont systemFontOfSize:19];
    self.titleLable.numberOfLines = 0;
    [scrollView addSubview:self.titleLable];
    
    NSDictionary * fontDict = @{NSFontAttributeName:[UIFont systemFontOfSize:19]};
    CGRect frameH = [self.model.Title boundingRectWithSize:CGSizeMake(BHscreenW-20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:fontDict context:nil];
    CGRect frameL = self.titleLable.frame;
    frameL.size.height = frameH.size.height;
    self.titleLable.frame = frameL;
    
    //时间
    self.timeLable = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLable.frame) + 14,w, 14)];
    self.timeLable.font = [UIFont systemFontOfSize:15];
    self.timeLable.textAlignment = NSTextAlignmentCenter;
    self.timeLable.textColor = [UIColor grayColor];
    self.timeLable.text = self.model.PublishTime;
    [scrollView addSubview:self.timeLable];
    
    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[self.model.NoticeContent dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    UITextView * textView = [[UITextView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.timeLable.frame), w, 20)];
    textView.attributedText = attrStr;
    textView.textColor = [UIColor grayColor];
    textView.font = [UIFont systemFontOfSize:15];
    textView.showsVerticalScrollIndicator = NO;
    textView.showsHorizontalScrollIndicator = NO;
    textView.userInteractionEnabled = NO;
    [scrollView addSubview:textView];
    CGSize size = [textView sizeThatFits:CGSizeMake(w, MAXFLOAT)];
    CGRect frame = textView.frame;
    frame.size.height = size.height;
    textView.frame = frame;
    float scorllViewH = CGRectGetMaxY(textView.frame);
    if(scorllViewH < BHscreenH-64-20){
        scrollView.frame = CGRectMake(10, 10, BHscreenH-20, scorllViewH);
    }
    scrollView.contentSize = CGSizeMake(w, scorllViewH);

}
#pragma mark - 消息数据
- (void)postMessageDetailData{
    
    NSDictionary * parms = @{
                             @"HandleType":@"1",
                             @"NoticeId":self.model.NoticeID,
                             @"UserID":@"0",
                             @"json":@"\{\"jsonEntity\":\{},\"action\":\"handlenotice\",\"version\":\"V1.0\"}"};
    DLog(@"消息的参数===%@",parms);
    
    [HomeNetWorkRequest postMarkMessageSuccess:^(id data) {

        NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        
        NSString * str = [NSString stringWithFormat:@"%@",dict[@"Data"]];
        NSData * data2 = [str dataUsingEncoding:NSUTF8StringEncoding];
        NSArray * array = [NSJSONSerialization JSONObjectWithData:data2 options:NSJSONReadingMutableContainers error:nil];
        DLog(@"消息详情数据 == %@",array);
        
        DLog(@"%@",dict[@"Msg"]);
        
        [MBProgressHUD hideHUDForView:self.view];
        
        
        [self.tableView reloadData];
        
    } Fail:^(NSString *errorDes) {
        
        [MBProgressHUD hideHUDForView:self.view];
        
        [MBProgressHUD hideHUD];
        
    } param:parms];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
  
    
}


@end
